
package com.bh.framework.controller;

import java.util.Vector;

public class AObject
{
	@SuppressWarnings("rawtypes")
	private Vector vectorListeners = new Vector();

	@SuppressWarnings("unchecked")
	public synchronized void addMyListener(AListener ml)
	{
		vectorListeners.addElement(ml);
	}

	public synchronized void removeMyListener(AListener ml)
	{
		vectorListeners.removeElement(ml);
	}

	protected void activateMyEvent()
	{
		AEvent e = new AEvent(this);
		activateMyEvent(e);
	}

	@SuppressWarnings("rawtypes")
	protected void activateMyEvent(AEvent e)
	{
		Vector tempVector = null;

		synchronized (this)
		{
			tempVector = (Vector) vectorListeners.clone();

			for (int i = 0; i < tempVector.size(); i++)
			{
				AListener ml = (AListener) tempVector.elementAt(i);
				ml.EventActivated(e);
			}
		}
	}

	// 定义一个公用方法用于触发事件
	public void Active()
	{
		activateMyEvent();
	}

	public void Active(AEvent e)
	{
		activateMyEvent(e);
	}
}
